package monitor;

import java.util.concurrent.Semaphore;

import lagern.LagerHelper;
import lagern.Monitor;
import lagern.MonitorHelper;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

public class Monitorclient {

	public static void main (String args[]) throws InterruptedException {
		MonitorImpl mC = new MonitorImpl();
		mC.hook = new Thread(new ShutdownActions(mC));
		Runtime.getRuntime().addShutdownHook(mC.hook);
		Semaphore sema= new Semaphore(0);
		ORB orb = null;
		
		try {
			orb = ORB.init(args, null);
			mC.orb = orb;
			POA rootPoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
			rootPoa.the_POAManager().activate();
			NamingContextExt nc = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
			org.omg.CORBA.Object obj = nc.resolve_str(args[4]);
			mC.lager =  LagerHelper.narrow(obj);	
			
			org.omg.CORBA.Object ref = rootPoa.servant_to_reference(mC);
			Monitor href = MonitorHelper.narrow(ref);
			mC.lager.aktiviereMonitor(href);
		}catch (Exception e) {
			System.err.println("ERROR: " + e);
			e.printStackTrace(System.out);	
		}
		
		orb.run();
	}
}
